
#ifndef protocol_h_
#define protocol_h_

/*
Message {
　　type: request|response|event,
	channel: 1|2|...		// 对象通道
　　body : RequestMessage|ResponseMessage|EventMessage
　}

RequestMessage结构，客户端发送到服务端,
{
　　action: action_id            // 操作id
　　parameters: list             // 参数列表
}
　　
ResponseMessage结构,  response 为服务端应答给客户端
{
　　action: action_id,           // 操作id
　　result: resultdata           // 应答数据
}

EventMessage结构，   事件操作
{
　　action: add|remove|notify,   // 添加消息监听，删除消息监听, 事件通知
　　id:    event_id,             // 事件id
　　parameters: list,            // 参数列表
}


*/

/*
#include <string>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/cstdint.hpp>

*/


namespace rpc {
  typedef Json::Value parameters;
}


namespace rpc { namespace protocol {


static const int message_request  = 0;
static const int message_response = 1;
static const int message_event    = 2;

static const int event_add		  = 0;
static const int event_remove	  = 1;
static const int event_notify	  = 2;


struct package_header
{
	boost::uint8_t sign[4];			// 签名 ORAY
	boost::uint32_t size;				// 数据包大小
};


static bool is_valid_package(const package_header& pkg_header) 
{
	return (strncmp((char*)pkg_header.sign, "wyxx", sizeof(pkg_header.sign)) == 0);
}

typedef struct _message {
	int type;
	int channel;
	std::string body;
	template <typename Archive>
	void serialize(Archive& ar)
	{
		ar & type;
		ar & channel;
		ar & body;
	}
} message;



class request : public serializer {
public:
	typedef boost::property_tree::ptree parameters;

public:
	request();
	request(const std::string& in_string);
	~request();

public:
	int action();
	void set_action(int func_id);
	parameters& params();
	void set_params(const parameters& p);
	void dump();
};

class response  : public serializer 
{
public:
	response();
	~response();

public:
	void put_result_code(int code);	
	int  get_result_code();
	void dump();
};

class event : public serializer
{
public:
	event();
	~event();

private:

};

} } // namespace protocol } namespace rpc


#endif // protocol_h_
